package com.Factory;

import com.Result.UserWithRelation;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.entity.Friend;
import com.entity.User;
import com.service.FriendService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

@Component
public class UserFactory {

    @Autowired
    private FriendService friendService;

    public UserWithRelation newUserWithRelation(User user, Integer userId1) {
        UserWithRelation userWithRelation = new UserWithRelation();
        BeanUtils.copyProperties(user, userWithRelation);
        if(user.getId().equals(userId1) || this.friendService.isFriend(userId1, user.getId())) {
            userWithRelation.setIsFriend(true);
        }else {
            userWithRelation.setIsFriend(false);
        }
        return userWithRelation;
    }

    public List<UserWithRelation> getUserWithRelationList(List<User> userList, Integer userId1) {
        return userList.stream().map(user -> this.newUserWithRelation(user, userId1)).collect(Collectors.toList());
    }
}
